<?php
namespace Admin\Controller;
use Think\Controller,
    Admin\Model\AclModel;

class IndexController extends Controller
{
    public function index()
    {
        $m_acl = new AclModel();

        $menus = null; $topmenus = null; $submenus = null; $tmp=null;

        if(session('admin_name')=='root' && session('admin_id')===1)
        {
            //如果是root帐号
            $tmp = $m_acl->getAclNode(2, array('st'=>1, 'lt_node_level'=>4), '*', null, null, 'px asc');
        }
        else
        {
            //其他帐号
            if(session('admin_acl')){
                $tmp = $m_acl->getAclNode(2, array('st'=>1, 'node_ids'=>session('admin_acl'), 'lt_node_level'=>4), '*', null, null, 'px asc');
            }
        }
        //整理
        $menus = list_to_tree($tmp, 'node_id', 'node_pid'); unset($tmp);

        foreach ($menus as $v){
            $topmenus[$v['node_id']] = $v; unset($topmenus[$v['node_id']]['_child']);
            $submenus[$v['node_id']] = $v['_child'];
        }
        unset($menus);

        $this->assign('topmenus', $topmenus);
        $this->assign('submenus', $submenus);
        $this->display();
    }

    public function home()
    {
        $info = array(
            '操作系统'=>PHP_OS,
            '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
            'PHP运行方式'=>php_sapi_name(),
            '上传附件限制'=>ini_get('upload_max_filesize'),
            '执行时间限制'=>ini_get('max_execution_time').'秒',
            '服务器时间'=>date("Y年n月j日 H:i:s"),
            '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+3600*8),
            '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            //'剩余空间'=>round((@disk_free_space(".")/(1024*1024)),2).'M',
            'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
            'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
            'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',
        );
        $this->assign('info', $info);
        $this->display();
    }

    public function pub_change_password()
    {
        if(IS_POST && isset($_POST['do'])){
            $post = I('post.');
            $m_acl = new AclModel();
            $rs = $m_acl->changePassword($post);
            if($rs['st'] == 'err'){ echo $rs['msg']; }
            else{ echo 'ok'; }
            exit;
        }
        $this->display();
    }

    public function pub_send_email()
    {
        $this->display();
    }

    public function pub_send_sms()
    {
        $this->display();
    }

    //打印session
    public function dump_session()
    {
        dump($_SESSION);
    }

    //打印cookie
    public function dump_cookie()
    {
        dump($_COOKIE);
    }

    //打印post
    public function dump_post()
    {
        dump($_POST);
    }

    //打印get
    public function dump_get()
    {
        dump($_GET);
    }

    //打印server
    public function dump_server()
    {
        dump($_SERVER);
    }

    //空方法
    public function _empty()
    {
        $this->redirect(U('admin/index/home'));
    }
}